﻿function Content() {


    this.sounds = [];
    this.videos = [];
    this.images = [];
    var i;

    this.loadContent = function (images, sounds, videos) {
        for (i = 0; i < images.length; i++) {
            this.addImage(images[i], images[i] + ".png", true);
        }
        for (i = 0; i < sounds.length; i++) {
            this.addSound(sounds[i], sounds[i] + ".mp3", true);
        }
        for (i = 0; i < sounds.length; i++) {
            this.addVideo(videos[i], videos[i] + ".mp4", true);
        }
    };


    function Sound(name, location, preLoad) {
        this.element = addElementToDocument("audio");
        this.element.src = "content/sounds/" + location.toString();
        this.element.setAttribute("class", "offScreen");
        this.name = name;
        if (preLoad) {
            this.element.load();
        }
        return this;
    }

    function Image(name, location, preLoad) {
      
        this.element = addElementToDocument("img");
        this.element.src = "content/images/" + location.toString();
        this.element.setAttribute("class", "offScreen");
        this.name = name;
//        if (preLoad)
//            this.element.load();
        return this;
    }


    function Video(name, location, preLoad) {
        this.element = addElementToDocument("video");
        this.element.src = location;
        this.element.setAttribute("class", "offScreen");
        this.name = name;
        if (preLoad) {
            this.element.load();
        }
        return this;

    }

    this.addSound = function (name, location, preLoad) {
        this.sounds.push(new Sound(name, location, preLoad));
    };

    this.addVideo = function (name, location, preLoad) {
        this.videos.push(new Video(name, location, preLoad));
    };

    this.addImage = function (name, location, preLoad) {
        this.images.push(new Image(name, location, preLoad));
    };

    this.playAudio = function (name) {
        // make work with audioelement
        var element = findArrayElement(name, this.sounds).element;
        element.play();
    };

    this.imageElement = function (name) {
        return findArrayElement(name, this.images).element;
    };

    this.audioElement = function (name) {
        return findArrayElement(name, this.sounds).element;
    };

    this.videoElement = function (name) {
        return findArrayElement(name, this.videos).element;
    };

    return this;
}
